{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 01- How to find the version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.4.1'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "pd.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "INSTALLED VERSIONS\n",
      "------------------\n",
      "commit           : 06d230151e6f18fdb8139d09abf539867a8cd481\n",
      "python           : 3.10.2.final.0\n",
      "python-bits      : 64\n",
      "OS               : Darwin\n",
      "OS-release       : 21.4.0\n",
      "Version          : Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000\n",
      "machine          : arm64\n",
      "processor        : arm\n",
      "byteorder        : little\n",
      "LC_ALL           : None\n",
      "LANG             : None\n",
      "LOCALE           : None.UTF-8\n",
      "\n",
      "pandas           : 1.4.1\n",
      "numpy            : 1.22.3\n",
      "pytz             : 2021.3\n",
      "dateutil         : 2.8.2\n",
      "pip              : 22.2\n",
      "setuptools       : 58.1.0\n",
      "Cython           : None\n",
      "pytest           : None\n",
      "hypothesis       : None\n",
      "sphinx           : None\n",
      "blosc            : None\n",
      "feather          : None\n",
      "xlsxwriter       : None\n",
      "lxml.etree       : None\n",
      "html5lib         : None\n",
      "pymysql          : None\n",
      "psycopg2         : None\n",
      "jinja2           : 3.1.1\n",
      "IPython          : 8.2.0\n",
      "pandas_datareader: None\n",
      "bs4              : 4.11.1\n",
      "bottleneck       : None\n",
      "fastparquet      : None\n",
      "fsspec           : None\n",
      "gcsfs            : None\n",
      "matplotlib       : 3.5.1\n",
      "numba            : None\n",
      "numexpr          : None\n",
      "odfpy            : None\n",
      "openpyxl         : 3.0.10\n",
      "pandas_gbq       : None\n",
      "pyarrow          : None\n",
      "pyreadstat       : None\n",
      "pyxlsb           : None\n",
      "s3fs             : None\n",
      "scipy            : 1.8.0\n",
      "sqlalchemy       : None\n",
      "tables           : None\n",
      "tabulate         : None\n",
      "xarray           : None\n",
      "xlrd             : None\n",
      "xlwt             : None\n",
      "zstandard        : None\n"
     ]
    }
   ],
   "source": [
    "# another way\n",
    "pd.show_versions()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 02- Make a dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A col</th>\n",
       "      <th>B col</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   A col  B col\n",
       "0      1      4\n",
       "1      2      5\n",
       "2      3      6\n",
       "3      6      7\n",
       "4      7      8"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({'A col': [1, 2, 3,6,7,8,9,22], 'B col': [4, 5, 6,7,8,9,10,11]})\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0  1  2\n",
       "0  1  2  3\n",
       "1  4  5  6\n",
       "2  7  8  9"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# numpy array use to create dataframe\n",
    "import numpy as np\n",
    "arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n",
    "pd.DataFrame(arr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.746385</td>\n",
       "      <td>0.615779</td>\n",
       "      <td>0.536173</td>\n",
       "      <td>0.117365</td>\n",
       "      <td>0.802371</td>\n",
       "      <td>0.193520</td>\n",
       "      <td>0.105354</td>\n",
       "      <td>0.511935</td>\n",
       "      <td>0.627011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.201784</td>\n",
       "      <td>0.601945</td>\n",
       "      <td>0.277574</td>\n",
       "      <td>0.026932</td>\n",
       "      <td>0.955200</td>\n",
       "      <td>0.608067</td>\n",
       "      <td>0.893448</td>\n",
       "      <td>0.650439</td>\n",
       "      <td>0.941738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.365113</td>\n",
       "      <td>0.387103</td>\n",
       "      <td>0.699454</td>\n",
       "      <td>0.013998</td>\n",
       "      <td>0.386100</td>\n",
       "      <td>0.738653</td>\n",
       "      <td>0.683039</td>\n",
       "      <td>0.538112</td>\n",
       "      <td>0.638939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.360623</td>\n",
       "      <td>0.700029</td>\n",
       "      <td>0.485148</td>\n",
       "      <td>0.352279</td>\n",
       "      <td>0.817625</td>\n",
       "      <td>0.905396</td>\n",
       "      <td>0.863746</td>\n",
       "      <td>0.338216</td>\n",
       "      <td>0.415760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.890056</td>\n",
       "      <td>0.103229</td>\n",
       "      <td>0.965295</td>\n",
       "      <td>0.408545</td>\n",
       "      <td>0.765464</td>\n",
       "      <td>0.218055</td>\n",
       "      <td>0.016816</td>\n",
       "      <td>0.465368</td>\n",
       "      <td>0.461771</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6  \\\n",
       "0  0.746385  0.615779  0.536173  0.117365  0.802371  0.193520  0.105354   \n",
       "1  0.201784  0.601945  0.277574  0.026932  0.955200  0.608067  0.893448   \n",
       "2  0.365113  0.387103  0.699454  0.013998  0.386100  0.738653  0.683039   \n",
       "3  0.360623  0.700029  0.485148  0.352279  0.817625  0.905396  0.863746   \n",
       "4  0.890056  0.103229  0.965295  0.408545  0.765464  0.218055  0.016816   \n",
       "\n",
       "          7         8  \n",
       "0  0.511935  0.627011  \n",
       "1  0.650439  0.941738  \n",
       "2  0.538112  0.638939  \n",
       "3  0.338216  0.415760  \n",
       "4  0.465368  0.461771  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# numpy array dataframe\n",
    "pd.DataFrame(np.random.rand(5,9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>G</th>\n",
       "      <th>H</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.061265</td>\n",
       "      <td>0.977084</td>\n",
       "      <td>0.458772</td>\n",
       "      <td>0.348452</td>\n",
       "      <td>0.021712</td>\n",
       "      <td>0.127061</td>\n",
       "      <td>0.887262</td>\n",
       "      <td>0.817084</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.701590</td>\n",
       "      <td>0.906653</td>\n",
       "      <td>0.152735</td>\n",
       "      <td>0.702853</td>\n",
       "      <td>0.539945</td>\n",
       "      <td>0.267058</td>\n",
       "      <td>0.984186</td>\n",
       "      <td>0.439089</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          A         B         C         D         E         F         G  \\\n",
       "0  0.061265  0.977084  0.458772  0.348452  0.021712  0.127061  0.887262   \n",
       "1  0.701590  0.906653  0.152735  0.702853  0.539945  0.267058  0.984186   \n",
       "\n",
       "          H  \n",
       "0  0.817084  \n",
       "1  0.439089  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(np.random.rand(2, 8), columns=list('ABCDEFGH'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3- How to rename columns?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A col</th>\n",
       "      <th>B col</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   A col  B col\n",
       "0      1      4\n",
       "1      2      5\n",
       "2      3      6\n",
       "3      6      7\n",
       "4      7      8\n",
       "5      8      9\n",
       "6      9     10\n",
       "7     22     11"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({'A col': [1, 2, 3,6,7,8,9,22], 'B col': [4, 5, 6,7,8,9,10,11]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_a</th>\n",
       "      <th>col_b</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col_a  col_b\n",
       "0      1      4\n",
       "1      2      5\n",
       "2      3      6\n",
       "3      6      7\n",
       "4      7      8\n",
       "5      8      9\n",
       "6      9     10\n",
       "7     22     11"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.rename(columns={'A col': 'col_a', 'B col': 'col_b'}, inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_aa</th>\n",
       "      <th>col_bb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col_aa  col_bb\n",
       "0       1       4\n",
       "1       2       5\n",
       "2       3       6\n",
       "3       6       7\n",
       "4       7       8\n",
       "5       8       9\n",
       "6       9      10\n",
       "7      22      11"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rename columns\n",
    "df.columns=['col_aa', 'col_bb']\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col aa</th>\n",
       "      <th>col bb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col aa  col bb\n",
       "0       1       4\n",
       "1       2       5\n",
       "2       3       6\n",
       "3       6       7\n",
       "4       7       8\n",
       "5       8       9\n",
       "6       9      10\n",
       "7      22      11"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# to replace any character, string\n",
    "df.columns=df.columns.str.replace('_', ' ')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_aa</th>\n",
       "      <th>col_bb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col_aa  col_bb\n",
       "0       1       4\n",
       "1       2       5\n",
       "2       3       6\n",
       "3       6       7\n",
       "4       7       8\n",
       "5       8       9\n",
       "6       9      10\n",
       "7      22      11"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns=df.columns.str.replace(' ', '_')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>baba_col_aa</th>\n",
       "      <th>baba_col_bb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   baba_col_aa  baba_col_bb\n",
       "0            1            4\n",
       "1            2            5\n",
       "2            3            6\n",
       "3            6            7\n",
       "4            7            8\n",
       "5            8            9\n",
       "6            9           10\n",
       "7           22           11"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Adding prefix to columns\n",
    "df = df.add_prefix('baba_')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>baba_col_aa_baba</th>\n",
       "      <th>baba_col_bb_baba</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   baba_col_aa_baba  baba_col_bb_baba\n",
       "0                 1                 4\n",
       "1                 2                 5\n",
       "2                 3                 6\n",
       "3                 6                 7\n",
       "4                 7                 8\n",
       "5                 8                 9\n",
       "6                 9                10\n",
       "7                22                11"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Adding suffix to columns\n",
    "df = df.add_suffix('_baba')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_a</th>\n",
       "      <th>col_b</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col_a  col_b\n",
       "0      1      4\n",
       "1      2      5\n",
       "2      3      6\n",
       "3      6      7\n",
       "4      7      8\n",
       "5      8      9\n",
       "6      9     10\n",
       "7     22     11"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns = ['col_a', 'col_b']\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4- Using template data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>total_bill</th>\n",
       "      <th>tip</th>\n",
       "      <th>sex</th>\n",
       "      <th>smoker</th>\n",
       "      <th>day</th>\n",
       "      <th>time</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>16.99</td>\n",
       "      <td>1.01</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10.34</td>\n",
       "      <td>1.66</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>21.01</td>\n",
       "      <td>3.50</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>23.68</td>\n",
       "      <td>3.31</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>24.59</td>\n",
       "      <td>3.61</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   total_bill   tip     sex smoker  day    time  size\n",
       "0       16.99  1.01  Female     No  Sun  Dinner     2\n",
       "1       10.34  1.66    Male     No  Sun  Dinner     3\n",
       "2       21.01  3.50    Male     No  Sun  Dinner     3\n",
       "3       23.68  3.31    Male     No  Sun  Dinner     2\n",
       "4       24.59  3.61  Female     No  Sun  Dinner     4"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from lib2to3.pygram import python_symbols\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "\n",
    "df = sns.load_dataset('tips')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size'], dtype='object')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# summary\n",
    "df.describe()\n",
    "\n",
    "# columns names\n",
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# saving a dataset\n",
    "df.to_csv('tips_save.csv')\n",
    "#pip install openpyxl\n",
    "df.to_excel('tips_save.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5- Using your own data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>total_bill</th>\n",
       "      <th>tip</th>\n",
       "      <th>sex</th>\n",
       "      <th>smoker</th>\n",
       "      <th>day</th>\n",
       "      <th>time</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>16.99</td>\n",
       "      <td>1.01</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>10.34</td>\n",
       "      <td>1.66</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>21.01</td>\n",
       "      <td>3.50</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>23.68</td>\n",
       "      <td>3.31</td>\n",
       "      <td>Male</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>24.59</td>\n",
       "      <td>3.61</td>\n",
       "      <td>Female</td>\n",
       "      <td>No</td>\n",
       "      <td>Sun</td>\n",
       "      <td>Dinner</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0  total_bill   tip     sex smoker  day    time  size\n",
       "0           0       16.99  1.01  Female     No  Sun  Dinner     2\n",
       "1           1       10.34  1.66    Male     No  Sun  Dinner     3\n",
       "2           2       21.01  3.50    Male     No  Sun  Dinner     3\n",
       "3           3       23.68  3.31    Male     No  Sun  Dinner     2\n",
       "4           4       24.59  3.61  Female     No  Sun  Dinner     4"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('tips_save.csv')\n",
    "df.head()\n",
    "df = pd.read_excel('tips_save.xlsx')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (2022.6.15)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install --upgrade certifi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 6- Reverse Row order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.4583</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "5         0       3    male   NaN      0      0   8.4583        Q  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  \n",
       "5    man        True  NaN   Queenstown    no   True  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import pandas as pd\n",
    "\n",
    "df = sns.load_dataset('titanic')\n",
    "df.head(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>890</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>32.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.75</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>male</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.00</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.45</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.00</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13.00</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     sex   age  sibsp  parch   fare embarked   class  \\\n",
       "890         0       3    male  32.0      0      0   7.75        Q   Third   \n",
       "889         1       1    male  26.0      0      0  30.00        C   First   \n",
       "888         0       3  female   NaN      1      2  23.45        S   Third   \n",
       "887         1       1  female  19.0      0      0  30.00        S   First   \n",
       "886         0       2    male  27.0      0      0  13.00        S  Second   \n",
       "\n",
       "       who  adult_male deck  embark_town alive  alone  \n",
       "890    man        True  NaN   Queenstown    no   True  \n",
       "889    man        True    C    Cherbourg   yes   True  \n",
       "888  woman       False  NaN  Southampton    no  False  \n",
       "887  woman       False    B  Southampton   yes   True  \n",
       "886    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[::-1].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>32.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.75</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>male</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.00</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.45</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.00</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13.00</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch   fare embarked   class  \\\n",
       "0         0       3    male  32.0      0      0   7.75        Q   Third   \n",
       "1         1       1    male  26.0      0      0  30.00        C   First   \n",
       "2         0       3  female   NaN      1      2  23.45        S   Third   \n",
       "3         1       1  female  19.0      0      0  30.00        S   First   \n",
       "4         0       2    male  27.0      0      0  13.00        S  Second   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN   Queenstown    no   True  \n",
       "1    man        True    C    Cherbourg   yes   True  \n",
       "2  woman       False  NaN  Southampton    no  False  \n",
       "3  woman       False    B  Southampton   yes   True  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[::-1].reset_index(drop=True).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7- Reverse column order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alone</th>\n",
       "      <th>alive</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>deck</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>who</th>\n",
       "      <th>class</th>\n",
       "      <th>embarked</th>\n",
       "      <th>fare</th>\n",
       "      <th>parch</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>age</th>\n",
       "      <th>sex</th>\n",
       "      <th>pclass</th>\n",
       "      <th>survived</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>no</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>man</td>\n",
       "      <td>Third</td>\n",
       "      <td>S</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>22.0</td>\n",
       "      <td>male</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>yes</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>C</td>\n",
       "      <td>False</td>\n",
       "      <td>woman</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>38.0</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>yes</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>woman</td>\n",
       "      <td>Third</td>\n",
       "      <td>S</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>female</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>yes</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>C</td>\n",
       "      <td>False</td>\n",
       "      <td>woman</td>\n",
       "      <td>First</td>\n",
       "      <td>S</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>female</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>no</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>man</td>\n",
       "      <td>Third</td>\n",
       "      <td>S</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>male</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   alone alive  embark_town deck  adult_male    who  class embarked     fare  \\\n",
       "0  False    no  Southampton  NaN        True    man  Third        S   7.2500   \n",
       "1  False   yes    Cherbourg    C       False  woman  First        C  71.2833   \n",
       "2   True   yes  Southampton  NaN       False  woman  Third        S   7.9250   \n",
       "3  False   yes  Southampton    C       False  woman  First        S  53.1000   \n",
       "4   True    no  Southampton  NaN        True    man  Third        S   8.0500   \n",
       "\n",
       "   parch  sibsp   age     sex  pclass  survived  \n",
       "0      0      1  22.0    male       3         0  \n",
       "1      0      1  38.0  female       1         1  \n",
       "2      0      0  26.0  female       3         1  \n",
       "3      0      1  35.0  female       1         1  \n",
       "4      0      0  35.0    male       3         0  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:, ::-1].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 8- select a column by dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "survived          int64\n",
       "pclass            int64\n",
       "sex              object\n",
       "age             float64\n",
       "sibsp             int64\n",
       "parch             int64\n",
       "fare            float64\n",
       "embarked         object\n",
       "class          category\n",
       "who              object\n",
       "adult_male         bool\n",
       "deck           category\n",
       "embark_town      object\n",
       "alive            object\n",
       "alone              bool\n",
       "dtype: object"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass   age  sibsp  parch     fare\n",
       "0         0       3  22.0      1      0   7.2500\n",
       "1         1       1  38.0      1      0  71.2833\n",
       "2         1       3  26.0      0      0   7.9250\n",
       "3         1       1  35.0      1      0  53.1000\n",
       "4         0       3  35.0      0      0   8.0500"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# only select those have numeric type\n",
    "df.select_dtypes(include=['number']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>embarked</th>\n",
       "      <th>who</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>male</td>\n",
       "      <td>S</td>\n",
       "      <td>man</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>female</td>\n",
       "      <td>C</td>\n",
       "      <td>woman</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>female</td>\n",
       "      <td>S</td>\n",
       "      <td>woman</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>female</td>\n",
       "      <td>S</td>\n",
       "      <td>woman</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>male</td>\n",
       "      <td>S</td>\n",
       "      <td>man</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      sex embarked    who  embark_town alive\n",
       "0    male        S    man  Southampton    no\n",
       "1  female        C  woman    Cherbourg   yes\n",
       "2  female        S  woman  Southampton   yes\n",
       "3  female        S  woman  Southampton   yes\n",
       "4    male        S    man  Southampton    no"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# only select those have object type\n",
    "df.select_dtypes(include=['object']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who deck  embark_town alive  \n",
       "0    man  NaN  Southampton    no  \n",
       "1  woman    C    Cherbourg   yes  \n",
       "2  woman  NaN  Southampton   yes  \n",
       "3  woman    C  Southampton   yes  \n",
       "4    man  NaN  Southampton    no  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# only select those have multiple type\n",
    "df.select_dtypes(include=['object', 'category', 'number']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>Third</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>First</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>Third</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>First</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>Third</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass   age  sibsp  parch     fare  class  adult_male deck  \\\n",
       "0         0       3  22.0      1      0   7.2500  Third        True  NaN   \n",
       "1         1       1  38.0      1      0  71.2833  First       False    C   \n",
       "2         1       3  26.0      0      0   7.9250  Third       False  NaN   \n",
       "3         1       1  35.0      1      0  53.1000  First       False    C   \n",
       "4         0       3  35.0      0      0   8.0500  Third        True  NaN   \n",
       "\n",
       "   alone  \n",
       "0  False  \n",
       "1  False  \n",
       "2   True  \n",
       "3  False  \n",
       "4   True  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.select_dtypes(exclude=['object']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 9- Convert strings to number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_A</th>\n",
       "      <th>col_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  col_A col_B\n",
       "0   1.2     4\n",
       "1     2     5\n",
       "2     3     6\n",
       "3     6     7\n",
       "4     7     8\n",
       "5     8     9\n",
       "6     9    10\n",
       "7    22    11"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({'col_A': ['1.2', '2', '3','6','7','8','9','22'], \n",
    "                    'col_B': ['4', '5', '6','7','8','9','10','11']})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "col_A    object\n",
       "col_B    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "col_A    float64\n",
       "col_B      int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.astype({'col_A': 'float64', 'col_B': 'int64'}).dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 10- Reduce dataframe size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(891, 15)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = sns.load_dataset('titanic')\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 891 entries, 0 to 890\n",
      "Data columns (total 15 columns):\n",
      " #   Column       Non-Null Count  Dtype   \n",
      "---  ------       --------------  -----   \n",
      " 0   survived     891 non-null    int64   \n",
      " 1   pclass       891 non-null    int64   \n",
      " 2   sex          891 non-null    object  \n",
      " 3   age          714 non-null    float64 \n",
      " 4   sibsp        891 non-null    int64   \n",
      " 5   parch        891 non-null    int64   \n",
      " 6   fare         891 non-null    float64 \n",
      " 7   embarked     889 non-null    object  \n",
      " 8   class        891 non-null    category\n",
      " 9   who          891 non-null    object  \n",
      " 10  adult_male   891 non-null    bool    \n",
      " 11  deck         203 non-null    category\n",
      " 12  embark_town  889 non-null    object  \n",
      " 13  alive        891 non-null    object  \n",
      " 14  alone        891 non-null    bool    \n",
      "dtypes: bool(2), category(2), float64(2), int64(4), object(5)\n",
      "memory usage: 80.7+ KB\n"
     ]
    }
   ],
   "source": [
    "df.sample(frac=0.1).shape\n",
    "df.info()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 11- Copy data from clip board"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dataset download\n",
    "import seaborn as sns\n",
    "import pandas as pd\n",
    "\n",
    "df = sns.load_dataset('titanic')\n",
    "df.to_excel('kashti.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# read clipboard in python\n",
    "df= pd.read_clipboard()\n",
    "df\n",
    "df.to_csv('excel ka data.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 12- split dataframe into two subsets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dataset download\n",
    "import seaborn as sns\n",
    "import pandas as pd\n",
    "df = sns.load_dataset('titanic')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "891"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(891, 15)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(446, 15)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from random import random\n",
    "kashti_1 = df.sample(frac=0.50, random_state=1)\n",
    "kashti_1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(445, 15)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kashti_2 = df.drop(kashti_1.index)\n",
    "kashti_2.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>862</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>48.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>25.9292</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>D</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>223</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.8958</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>17.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.5000</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>680</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.1375</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>535</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>7.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>26.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "862         1       1  female  48.0      0      0  25.9292        S   First   \n",
       "223         0       3    male   NaN      0      0   7.8958        S   Third   \n",
       "84          1       2  female  17.0      0      0  10.5000        S  Second   \n",
       "680         0       3  female   NaN      0      0   8.1375        Q   Third   \n",
       "535         1       2  female   7.0      0      2  26.2500        S  Second   \n",
       "\n",
       "       who  adult_male deck  embark_town alive  alone  \n",
       "862  woman       False    D  Southampton   yes   True  \n",
       "223    man        True  NaN  Southampton    no   True  \n",
       "84   woman       False  NaN  Southampton   yes   True  \n",
       "680  woman       False  NaN   Queenstown    no   True  \n",
       "535  child       False  NaN  Southampton   yes  False  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kashti_1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>21.0750</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>16.7000</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>G</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>55.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>31.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>18.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "1          1       1  female  38.0      1      0  71.2833        C   First   \n",
       "7          0       3    male   2.0      3      1  21.0750        S   Third   \n",
       "10         1       3  female   4.0      1      1  16.7000        S   Third   \n",
       "15         1       2  female  55.0      0      0  16.0000        S  Second   \n",
       "18         0       3  female  31.0      1      0  18.0000        S   Third   \n",
       "\n",
       "      who  adult_male deck  embark_town alive  alone  \n",
       "1   woman       False    C    Cherbourg   yes  False  \n",
       "7   child       False  NaN  Southampton    no  False  \n",
       "10  child       False    G  Southampton   yes  False  \n",
       "15  woman       False  NaN  Southampton   yes   True  \n",
       "18  woman       False  NaN  Southampton    no  False  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kashti_2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(891, 15)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "891"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(kashti_1) + len(kashti_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 13- Join two datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/nf/j0gr9tfn3gg2ln2c25rl4wnc0000gn/T/ipykernel_83078/2262909734.py:1: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.\n",
      "  df1 = kashti_1.append(kashti_2)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(891, 15)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = kashti_1.append(kashti_2)\n",
    "df1.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 14- Filtering a dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['male', 'female'], dtype=object)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sex.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>11.1333</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0708</td>\n",
       "      <td>C</td>\n",
       "      <td>Second</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>26.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>882</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.5167</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>29.1250</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.4500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>314 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "1           1       1  female  38.0      1      0  71.2833        C   First   \n",
       "2           1       3  female  26.0      0      0   7.9250        S   Third   \n",
       "3           1       1  female  35.0      1      0  53.1000        S   First   \n",
       "8           1       3  female  27.0      0      2  11.1333        S   Third   \n",
       "9           1       2  female  14.0      1      0  30.0708        C  Second   \n",
       "..        ...     ...     ...   ...    ...    ...      ...      ...     ...   \n",
       "880         1       2  female  25.0      0      1  26.0000        S  Second   \n",
       "882         0       3  female  22.0      0      0  10.5167        S   Third   \n",
       "885         0       3  female  39.0      0      5  29.1250        Q   Third   \n",
       "887         1       1  female  19.0      0      0  30.0000        S   First   \n",
       "888         0       3  female   NaN      1      2  23.4500        S   Third   \n",
       "\n",
       "       who  adult_male deck  embark_town alive  alone  \n",
       "1    woman       False    C    Cherbourg   yes  False  \n",
       "2    woman       False  NaN  Southampton   yes   True  \n",
       "3    woman       False    C  Southampton   yes  False  \n",
       "8    woman       False  NaN  Southampton   yes  False  \n",
       "9    child       False  NaN    Cherbourg   yes  False  \n",
       "..     ...         ...  ...          ...   ...    ...  \n",
       "880  woman       False  NaN  Southampton   yes  False  \n",
       "882  woman       False  NaN  Southampton    no   True  \n",
       "885  woman       False  NaN   Queenstown    no  False  \n",
       "887  woman       False    B  Southampton   yes   True  \n",
       "888  woman       False  NaN  Southampton    no  False  \n",
       "\n",
       "[314 rows x 15 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df.sex==\"female\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Southampton' 'Cherbourg' 'Queenstown' nan]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(644, 15)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(df.embark_town.unique())\n",
    "df[(df.embark_town=='Southampton')].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>11.1333</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>16.7000</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>G</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.5500</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>26.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>882</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>22.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.5167</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>39.0</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>29.1250</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.4500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>239 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "2           1       3  female  26.0      0      0   7.9250        S   Third   \n",
       "3           1       1  female  35.0      1      0  53.1000        S   First   \n",
       "8           1       3  female  27.0      0      2  11.1333        S   Third   \n",
       "10          1       3  female   4.0      1      1  16.7000        S   Third   \n",
       "11          1       1  female  58.0      0      0  26.5500        S   First   \n",
       "..        ...     ...     ...   ...    ...    ...      ...      ...     ...   \n",
       "880         1       2  female  25.0      0      1  26.0000        S  Second   \n",
       "882         0       3  female  22.0      0      0  10.5167        S   Third   \n",
       "885         0       3  female  39.0      0      5  29.1250        Q   Third   \n",
       "887         1       1  female  19.0      0      0  30.0000        S   First   \n",
       "888         0       3  female   NaN      1      2  23.4500        S   Third   \n",
       "\n",
       "       who  adult_male deck  embark_town alive  alone  \n",
       "2    woman       False  NaN  Southampton   yes   True  \n",
       "3    woman       False    C  Southampton   yes  False  \n",
       "8    woman       False  NaN  Southampton   yes  False  \n",
       "10   child       False    G  Southampton   yes  False  \n",
       "11   woman       False    C  Southampton   yes   True  \n",
       "..     ...         ...  ...          ...   ...    ...  \n",
       "880  woman       False  NaN  Southampton   yes  False  \n",
       "882  woman       False  NaN  Southampton    no   True  \n",
       "885  woman       False  NaN   Queenstown    no  False  \n",
       "887  woman       False    B  Southampton   yes   True  \n",
       "888  woman       False  NaN  Southampton    no  False  \n",
       "\n",
       "[239 rows x 15 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[((df.embark_town=='Southampton')|\n",
    "    (df.embark_town=='Queenstown')) & \n",
    "    (df.sex==\"female\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.4583</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "5         0       3    male   NaN      0      0   8.4583        Q  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  \n",
       "5    man        True  NaN   Queenstown    no   True  "
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.embark_town.isin(['Queenstown', 'Southampton'])].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(113, 15)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.age < 18].shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 15- Filtering by large categories"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24.0    30\n",
       "22.0    27\n",
       "18.0    26\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.age.value_counts().nlargest(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "man      537\n",
       "woman    271\n",
       "child     83\n",
       "Name: who, dtype: int64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "counts = df.who.value_counts()\n",
    "counts.nlargest(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.who.isin(counts.nlargest(2).index)].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 16- Splitting a string into multiple columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ahmad Raza</td>\n",
       "      <td>Lahore, Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ali Afzal</td>\n",
       "      <td>Sargodha, Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sajjad Ali</td>\n",
       "      <td>Karachi, Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Abu Bakkar</td>\n",
       "      <td>Hamburg, Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         name            location\n",
       "0  Ahmad Raza    Lahore, Pakistan\n",
       "1   Ali Afzal  Sargodha, Pakistan\n",
       "2  Sajjad Ali   Karachi, Pakistan\n",
       "3  Abu Bakkar    Hamburg, Germany"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# import libraries\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({'name':['Ahmad Raza', 'Ali Afzal', 'Sajjad Ali', 'Abu Bakkar'],\n",
    "                   'location':['Lahore, Pakistan', 'Sargodha, Pakistan', 'Karachi, Pakistan', 'Hamburg, Germany']})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ahmad</td>\n",
       "      <td>Raza</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ali</td>\n",
       "      <td>Afzal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sajjad</td>\n",
       "      <td>Ali</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Abu</td>\n",
       "      <td>Bakkar</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        0       1\n",
       "0   Ahmad    Raza\n",
       "1     Ali   Afzal\n",
       "2  Sajjad     Ali\n",
       "3     Abu  Bakkar"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# spliting a column into two columns\n",
    "df.name.str.split(' ', expand=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ahmad Raza</td>\n",
       "      <td>Lahore, Pakistan</td>\n",
       "      <td>Ahmad</td>\n",
       "      <td>Raza</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ali Afzal</td>\n",
       "      <td>Sargodha, Pakistan</td>\n",
       "      <td>Ali</td>\n",
       "      <td>Afzal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sajjad Ali</td>\n",
       "      <td>Karachi, Pakistan</td>\n",
       "      <td>Sajjad</td>\n",
       "      <td>Ali</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Abu Bakkar</td>\n",
       "      <td>Hamburg, Germany</td>\n",
       "      <td>Abu</td>\n",
       "      <td>Bakkar</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         name            location first_name last_name\n",
       "0  Ahmad Raza    Lahore, Pakistan      Ahmad      Raza\n",
       "1   Ali Afzal  Sargodha, Pakistan        Ali     Afzal\n",
       "2  Sajjad Ali   Karachi, Pakistan     Sajjad       Ali\n",
       "3  Abu Bakkar    Hamburg, Germany        Abu    Bakkar"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# adding those splits into new columns\n",
    "df[[\"first_name\", \"last_name\"]] = df.name.str.split(' ', expand=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>location</th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ahmad Raza</td>\n",
       "      <td>Lahore, Pakistan</td>\n",
       "      <td>Ahmad</td>\n",
       "      <td>Raza</td>\n",
       "      <td>Lahore</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ali Afzal</td>\n",
       "      <td>Sargodha, Pakistan</td>\n",
       "      <td>Ali</td>\n",
       "      <td>Afzal</td>\n",
       "      <td>Sargodha</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sajjad Ali</td>\n",
       "      <td>Karachi, Pakistan</td>\n",
       "      <td>Sajjad</td>\n",
       "      <td>Ali</td>\n",
       "      <td>Karachi</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Abu Bakkar</td>\n",
       "      <td>Hamburg, Germany</td>\n",
       "      <td>Abu</td>\n",
       "      <td>Bakkar</td>\n",
       "      <td>Hamburg</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         name            location first_name last_name      city   country\n",
       "0  Ahmad Raza    Lahore, Pakistan      Ahmad      Raza    Lahore  Pakistan\n",
       "1   Ali Afzal  Sargodha, Pakistan        Ali     Afzal  Sargodha  Pakistan\n",
       "2  Sajjad Ali   Karachi, Pakistan     Sajjad       Ali   Karachi  Pakistan\n",
       "3  Abu Bakkar    Hamburg, Germany        Abu    Bakkar   Hamburg   Germany"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[[\"city\", \"country\"]] = df.location.str.split(', ', expand=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>first_name</th>\n",
       "      <th>last_name</th>\n",
       "      <th>city</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Ahmad</td>\n",
       "      <td>Raza</td>\n",
       "      <td>Lahore</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Ali</td>\n",
       "      <td>Afzal</td>\n",
       "      <td>Sargodha</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sajjad</td>\n",
       "      <td>Ali</td>\n",
       "      <td>Karachi</td>\n",
       "      <td>Pakistan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Abu</td>\n",
       "      <td>Bakkar</td>\n",
       "      <td>Hamburg</td>\n",
       "      <td>Germany</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  first_name last_name      city   country\n",
       "0      Ahmad      Raza    Lahore  Pakistan\n",
       "1        Ali     Afzal  Sargodha  Pakistan\n",
       "2     Sajjad       Ali   Karachi  Pakistan\n",
       "3        Abu    Bakkar   Hamburg   Germany"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Refine data manipulation\n",
    "df = df[['first_name', 'last_name', 'city', 'country']]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 17- Aggregate by multiple groups/function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# libraries \n",
    "import pandas as pd\n",
    "import seaborn as sns\\\n",
    "\n",
    "# import dataset\n",
    "df = sns.load_dataset('titanic')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>female</th>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "      <td>261</td>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "      <td>312</td>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "      <td>97</td>\n",
       "      <td>312</td>\n",
       "      <td>314</td>\n",
       "      <td>314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>male</th>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>453</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>106</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "      <td>577</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        survived  pclass  age  sibsp  parch  fare  embarked  class  who  \\\n",
       "sex                                                                       \n",
       "female       314     314  261    314    314   314       312    314  314   \n",
       "male         577     577  453    577    577   577       577    577  577   \n",
       "\n",
       "        adult_male  deck  embark_town  alive  alone  \n",
       "sex                                                  \n",
       "female         314    97          312    314    314  \n",
       "male           577   106          577    577    577  "
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('sex').count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>who</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>child</th>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>13</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>man</th>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>413</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>99</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>woman</th>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "      <td>218</td>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "      <td>269</td>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "      <td>91</td>\n",
       "      <td>269</td>\n",
       "      <td>271</td>\n",
       "      <td>271</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       survived  pclass  sex  age  sibsp  parch  fare  embarked  class  \\\n",
       "who                                                                      \n",
       "child        83      83   83   83     83     83    83        83     83   \n",
       "man         537     537  537  413    537    537   537       537    537   \n",
       "woman       271     271  271  218    271    271   271       269    271   \n",
       "\n",
       "       adult_male  deck  embark_town  alive  alone  \n",
       "who                                                 \n",
       "child          83    13           83     83     83  \n",
       "man           537    99          537    537    537  \n",
       "woman         271    91          269    271    271  "
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('who').count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df.groupby('pclass'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>pclass</th>\n",
       "      <th>embarked</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"9\" valign=\"top\">female</th>\n",
       "      <th rowspan=\"3\" valign=\"top\">1</th>\n",
       "      <th>C</th>\n",
       "      <td>43</td>\n",
       "      <td>38</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>35</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>48</td>\n",
       "      <td>44</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>43</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2</th>\n",
       "      <th>C</th>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>67</td>\n",
       "      <td>66</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>8</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">3</th>\n",
       "      <th>C</th>\n",
       "      <td>23</td>\n",
       "      <td>16</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>33</td>\n",
       "      <td>10</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>88</td>\n",
       "      <td>76</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>5</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"9\" valign=\"top\">male</th>\n",
       "      <th rowspan=\"3\" valign=\"top\">1</th>\n",
       "      <th>C</th>\n",
       "      <td>42</td>\n",
       "      <td>36</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>31</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>79</td>\n",
       "      <td>64</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>62</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">2</th>\n",
       "      <th>C</th>\n",
       "      <td>10</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>97</td>\n",
       "      <td>90</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>5</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">3</th>\n",
       "      <th>C</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>0</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>39</td>\n",
       "      <td>14</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>1</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>265</td>\n",
       "      <td>214</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>5</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "      <td>265</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        survived  age  sibsp  parch  fare  class  who  \\\n",
       "sex    pclass embarked                                                  \n",
       "female 1      C               43   38     43     43    43     43   43   \n",
       "              Q                1    1      1      1     1      1    1   \n",
       "              S               48   44     48     48    48     48   48   \n",
       "       2      C                7    7      7      7     7      7    7   \n",
       "              Q                2    1      2      2     2      2    2   \n",
       "              S               67   66     67     67    67     67   67   \n",
       "       3      C               23   16     23     23    23     23   23   \n",
       "              Q               33   10     33     33    33     33   33   \n",
       "              S               88   76     88     88    88     88   88   \n",
       "male   1      C               42   36     42     42    42     42   42   \n",
       "              Q                1    1      1      1     1      1    1   \n",
       "              S               79   64     79     79    79     79   79   \n",
       "       2      C               10    8     10     10    10     10   10   \n",
       "              Q                1    1      1      1     1      1    1   \n",
       "              S               97   90     97     97    97     97   97   \n",
       "       3      C               43   25     43     43    43     43   43   \n",
       "              Q               39   14     39     39    39     39   39   \n",
       "              S              265  214    265    265   265    265  265   \n",
       "\n",
       "                        adult_male  deck  embark_town  alive  alone  \n",
       "sex    pclass embarked                                               \n",
       "female 1      C                 43    35           43     43     43  \n",
       "              Q                  1     1            1      1      1  \n",
       "              S                 48    43           48     48     48  \n",
       "       2      C                  7     1            7      7      7  \n",
       "              Q                  2     1            2      2      2  \n",
       "              S                 67     8           67     67     67  \n",
       "       3      C                 23     1           23     23     23  \n",
       "              Q                 33     0           33     33     33  \n",
       "              S                 88     5           88     88     88  \n",
       "male   1      C                 42    31           42     42     42  \n",
       "              Q                  1     1            1      1      1  \n",
       "              S                 79    62           79     79     79  \n",
       "       2      C                 10     1           10     10     10  \n",
       "              Q                  1     0            1      1      1  \n",
       "              S                 97     5           97     97     97  \n",
       "       3      C                 43     0           43     43     43  \n",
       "              Q                 39     1           39     39     39  \n",
       "              S                265     5          265    265    265  "
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['sex', 'pclass', 'embarked']).count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 18- select specific rows or column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>male</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>13.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>Second</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>B</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>23.4500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>male</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0000</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>890</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>32.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.7500</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>891 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "0           0       3    male  22.0      1      0   7.2500        S   Third   \n",
       "1           1       1  female  38.0      1      0  71.2833        C   First   \n",
       "2           1       3  female  26.0      0      0   7.9250        S   Third   \n",
       "3           1       1  female  35.0      1      0  53.1000        S   First   \n",
       "4           0       3    male  35.0      0      0   8.0500        S   Third   \n",
       "..        ...     ...     ...   ...    ...    ...      ...      ...     ...   \n",
       "886         0       2    male  27.0      0      0  13.0000        S  Second   \n",
       "887         1       1  female  19.0      0      0  30.0000        S   First   \n",
       "888         0       3  female   NaN      1      2  23.4500        S   Third   \n",
       "889         1       1    male  26.0      0      0  30.0000        C   First   \n",
       "890         0       3    male  32.0      0      0   7.7500        Q   Third   \n",
       "\n",
       "       who  adult_male deck  embark_town alive  alone  \n",
       "0      man        True  NaN  Southampton    no  False  \n",
       "1    woman       False    C    Cherbourg   yes  False  \n",
       "2    woman       False  NaN  Southampton   yes   True  \n",
       "3    woman       False    C  Southampton   yes  False  \n",
       "4      man        True  NaN  Southampton    no   True  \n",
       "..     ...         ...  ...          ...   ...    ...  \n",
       "886    man        True  NaN  Southampton    no   True  \n",
       "887  woman       False    B  Southampton   yes   True  \n",
       "888  woman       False  NaN  Southampton    no  False  \n",
       "889    man        True    C    Cherbourg   yes   True  \n",
       "890    man        True  NaN   Queenstown    no   True  \n",
       "\n",
       "[891 rows x 15 columns]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>male</td>\n",
       "      <td>Third</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>female</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>female</td>\n",
       "      <td>Third</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>female</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>male</td>\n",
       "      <td>Third</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>male</td>\n",
       "      <td>Second</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>female</td>\n",
       "      <td>First</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>female</td>\n",
       "      <td>Third</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>male</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>890</th>\n",
       "      <td>male</td>\n",
       "      <td>Third</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>891 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        sex   class deck\n",
       "0      male   Third  NaN\n",
       "1    female   First    C\n",
       "2    female   Third  NaN\n",
       "3    female   First    C\n",
       "4      male   Third  NaN\n",
       "..      ...     ...  ...\n",
       "886    male  Second  NaN\n",
       "887  female   First    B\n",
       "888  female   Third  NaN\n",
       "889    male   First    C\n",
       "890    male   Third  NaN\n",
       "\n",
       "[891 rows x 3 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select columns\n",
    "df[['sex', 'class', 'deck']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>891.000000</td>\n",
       "      <td>891.000000</td>\n",
       "      <td>714.000000</td>\n",
       "      <td>891.000000</td>\n",
       "      <td>891.000000</td>\n",
       "      <td>891.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.383838</td>\n",
       "      <td>2.308642</td>\n",
       "      <td>29.699118</td>\n",
       "      <td>0.523008</td>\n",
       "      <td>0.381594</td>\n",
       "      <td>32.204208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.486592</td>\n",
       "      <td>0.836071</td>\n",
       "      <td>14.526497</td>\n",
       "      <td>1.102743</td>\n",
       "      <td>0.806057</td>\n",
       "      <td>49.693429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.420000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>20.125000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>7.910400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>14.454200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>38.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>31.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>80.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>512.329200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         survived      pclass         age       sibsp       parch        fare\n",
       "count  891.000000  891.000000  714.000000  891.000000  891.000000  891.000000\n",
       "mean     0.383838    2.308642   29.699118    0.523008    0.381594   32.204208\n",
       "std      0.486592    0.836071   14.526497    1.102743    0.806057   49.693429\n",
       "min      0.000000    1.000000    0.420000    0.000000    0.000000    0.000000\n",
       "25%      0.000000    2.000000   20.125000    0.000000    0.000000    7.910400\n",
       "50%      0.000000    3.000000   28.000000    0.000000    0.000000   14.454200\n",
       "75%      1.000000    3.000000   38.000000    1.000000    0.000000   31.000000\n",
       "max      1.000000    3.000000   80.000000    8.000000    6.000000  512.329200"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.420</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>20.125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.9104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>28.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>14.4542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>38.000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>31.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>80.000</td>\n",
       "      <td>8.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>512.3292</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     age  sibsp  parch      fare\n",
       "min       0.0     1.0   0.420    0.0    0.0    0.0000\n",
       "25%       0.0     2.0  20.125    0.0    0.0    7.9104\n",
       "50%       0.0     3.0  28.000    0.0    0.0   14.4542\n",
       "75%       1.0     3.0  38.000    1.0    0.0   31.0000\n",
       "max       1.0     3.0  80.000    8.0    6.0  512.3292"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df.describe().loc[['min', '25%', '50%', '75%', 'max']]\n",
    "#or\n",
    "df.describe().loc['min':'max']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>20.125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>28.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>38.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>80.000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     survived  pclass     age\n",
       "min       0.0     1.0   0.420\n",
       "25%       0.0     2.0  20.125\n",
       "50%       0.0     3.0  28.000\n",
       "75%       1.0     3.0  38.000\n",
       "max       1.0     3.0  80.000"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe().loc['min':'max', 'survived':'age']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 19- Reshape multiindex series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3838383838383838"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.survived.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex\n",
       "female    0.742038\n",
       "male      0.188908\n",
       "Name: survived, dtype: float64"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('sex').survived.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex     class \n",
       "female  First     0.968085\n",
       "        Second    0.921053\n",
       "        Third     0.500000\n",
       "male    First     0.368852\n",
       "        Second    0.157407\n",
       "        Third     0.135447\n",
       "Name: survived, dtype: float64"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['sex','class']).survived.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex     pclass\n",
       "female  1         0.968085\n",
       "        2         0.921053\n",
       "        3         0.500000\n",
       "male    1         0.368852\n",
       "        2         0.157407\n",
       "        3         0.135447\n",
       "Name: survived, dtype: float64"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['sex','pclass']).survived.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 20- Continuous to catogirical data conversion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone  \n",
       "0    man        True  NaN  Southampton    no  False  \n",
       "1  woman       False    C    Cherbourg   yes  False  \n",
       "2  woman       False  NaN  Southampton   yes   True  \n",
       "3  woman       False    C  Southampton   yes  False  \n",
       "4    man        True  NaN  Southampton    no   True  "
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    22.0\n",
       "1    38.0\n",
       "2    26.0\n",
       "3    35.0\n",
       "4    35.0\n",
       "Name: age, dtype: float64"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.age.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "      <th>new_age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "      <td>young_adult</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone      new_age  \n",
       "0    man        True  NaN  Southampton    no  False  young_adult  \n",
       "1  woman       False    C    Cherbourg   yes  False        adult  \n",
       "2  woman       False  NaN  Southampton   yes   True        adult  \n",
       "3  woman       False    C  Southampton   yes  False        adult  \n",
       "4    man        True  NaN  Southampton    no   True        adult  "
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#creating bins\n",
    "pd.cut(df.age, bins = [0, 18, 25, 99], labels=['child', 'young_adult', 'adult']).head()\n",
    "df['new_age'] = pd.cut(df.age, bins = [0, 18, 25, 99], labels=['child', 'young_adult', 'adult'])\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 21- convert one set of values into anotherone"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      male\n",
       "1    female\n",
       "2    female\n",
       "3    female\n",
       "4      male\n",
       "Name: sex, dtype: object"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sex.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "      <th>new_age</th>\n",
       "      <th>sex_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "      <td>young_adult</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   survived  pclass     sex   age  sibsp  parch     fare embarked  class  \\\n",
       "0         0       3    male  22.0      1      0   7.2500        S  Third   \n",
       "1         1       1  female  38.0      1      0  71.2833        C  First   \n",
       "2         1       3  female  26.0      0      0   7.9250        S  Third   \n",
       "3         1       1  female  35.0      1      0  53.1000        S  First   \n",
       "4         0       3    male  35.0      0      0   8.0500        S  Third   \n",
       "\n",
       "     who  adult_male deck  embark_town alive  alone      new_age  sex_num  \n",
       "0    man        True  NaN  Southampton    no  False  young_adult        0  \n",
       "1  woman       False    C    Cherbourg   yes  False        adult        1  \n",
       "2  woman       False  NaN  Southampton   yes   True        adult        1  \n",
       "3  woman       False    C  Southampton   yes  False        adult        1  \n",
       "4    man        True  NaN  Southampton    no   True        adult        0  "
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['sex_num'] = df.sex.map({'male':0, 'female':1})\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['S', 'C', 'Q', nan], dtype=object)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.embarked.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>survived</th>\n",
       "      <th>pclass</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>sibsp</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>embarked</th>\n",
       "      <th>class</th>\n",
       "      <th>who</th>\n",
       "      <th>adult_male</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alive</th>\n",
       "      <th>alone</th>\n",
       "      <th>new_age</th>\n",
       "      <th>sex_num</th>\n",
       "      <th>embarked_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "      <td>young_adult</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.4583</td>\n",
       "      <td>Q</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>male</td>\n",
       "      <td>54.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>51.8625</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>E</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>21.0750</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "      <td>child</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>11.1333</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>female</td>\n",
       "      <td>14.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>30.0708</td>\n",
       "      <td>C</td>\n",
       "      <td>Second</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>child</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>16.7000</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>G</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>False</td>\n",
       "      <td>child</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>female</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>26.5500</td>\n",
       "      <td>S</td>\n",
       "      <td>First</td>\n",
       "      <td>woman</td>\n",
       "      <td>False</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>yes</td>\n",
       "      <td>True</td>\n",
       "      <td>adult</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>young_adult</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>male</td>\n",
       "      <td>39.0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>31.2750</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>man</td>\n",
       "      <td>True</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>False</td>\n",
       "      <td>adult</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>female</td>\n",
       "      <td>14.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.8542</td>\n",
       "      <td>S</td>\n",
       "      <td>Third</td>\n",
       "      <td>child</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>no</td>\n",
       "      <td>True</td>\n",
       "      <td>child</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    survived  pclass     sex   age  sibsp  parch     fare embarked   class  \\\n",
       "0          0       3    male  22.0      1      0   7.2500        S   Third   \n",
       "1          1       1  female  38.0      1      0  71.2833        C   First   \n",
       "2          1       3  female  26.0      0      0   7.9250        S   Third   \n",
       "3          1       1  female  35.0      1      0  53.1000        S   First   \n",
       "4          0       3    male  35.0      0      0   8.0500        S   Third   \n",
       "5          0       3    male   NaN      0      0   8.4583        Q   Third   \n",
       "6          0       1    male  54.0      0      0  51.8625        S   First   \n",
       "7          0       3    male   2.0      3      1  21.0750        S   Third   \n",
       "8          1       3  female  27.0      0      2  11.1333        S   Third   \n",
       "9          1       2  female  14.0      1      0  30.0708        C  Second   \n",
       "10         1       3  female   4.0      1      1  16.7000        S   Third   \n",
       "11         1       1  female  58.0      0      0  26.5500        S   First   \n",
       "12         0       3    male  20.0      0      0   8.0500        S   Third   \n",
       "13         0       3    male  39.0      1      5  31.2750        S   Third   \n",
       "14         0       3  female  14.0      0      0   7.8542        S   Third   \n",
       "\n",
       "      who  adult_male deck  embark_town alive  alone      new_age  sex_num  \\\n",
       "0     man        True  NaN  Southampton    no  False  young_adult        0   \n",
       "1   woman       False    C    Cherbourg   yes  False        adult        1   \n",
       "2   woman       False  NaN  Southampton   yes   True        adult        1   \n",
       "3   woman       False    C  Southampton   yes  False        adult        1   \n",
       "4     man        True  NaN  Southampton    no   True        adult        0   \n",
       "5     man        True  NaN   Queenstown    no   True          NaN        0   \n",
       "6     man        True    E  Southampton    no   True        adult        0   \n",
       "7   child       False  NaN  Southampton    no  False        child        0   \n",
       "8   woman       False  NaN  Southampton   yes  False        adult        1   \n",
       "9   child       False  NaN    Cherbourg   yes  False        child        1   \n",
       "10  child       False    G  Southampton   yes  False        child        1   \n",
       "11  woman       False    C  Southampton   yes   True        adult        1   \n",
       "12    man        True  NaN  Southampton    no   True  young_adult        0   \n",
       "13    man        True  NaN  Southampton    no  False        adult        0   \n",
       "14  child       False  NaN  Southampton    no   True        child        1   \n",
       "\n",
       "    embarked_num  \n",
       "0              0  \n",
       "1              1  \n",
       "2              0  \n",
       "3              0  \n",
       "4              0  \n",
       "5              2  \n",
       "6              0  \n",
       "7              0  \n",
       "8              0  \n",
       "9              1  \n",
       "10             0  \n",
       "11             0  \n",
       "12             0  \n",
       "13             0  \n",
       "14             0  "
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['embarked_num'] = df.embarked.factorize()[0]\n",
    "df.head(15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 22- transpose a wide dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>d</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "      <th>g</th>\n",
       "      <th>h</th>\n",
       "      <th>i</th>\n",
       "      <th>j</th>\n",
       "      <th>...</th>\n",
       "      <th>p</th>\n",
       "      <th>q</th>\n",
       "      <th>r</th>\n",
       "      <th>s</th>\n",
       "      <th>t</th>\n",
       "      <th>u</th>\n",
       "      <th>v</th>\n",
       "      <th>w</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.950685</td>\n",
       "      <td>0.645378</td>\n",
       "      <td>0.313912</td>\n",
       "      <td>0.736112</td>\n",
       "      <td>0.857305</td>\n",
       "      <td>0.374970</td>\n",
       "      <td>0.234014</td>\n",
       "      <td>0.782537</td>\n",
       "      <td>0.342148</td>\n",
       "      <td>0.522992</td>\n",
       "      <td>...</td>\n",
       "      <td>0.050619</td>\n",
       "      <td>0.453605</td>\n",
       "      <td>0.270995</td>\n",
       "      <td>0.031629</td>\n",
       "      <td>0.574733</td>\n",
       "      <td>0.897325</td>\n",
       "      <td>0.501739</td>\n",
       "      <td>0.656413</td>\n",
       "      <td>0.899499</td>\n",
       "      <td>0.601801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.696237</td>\n",
       "      <td>0.926854</td>\n",
       "      <td>0.188815</td>\n",
       "      <td>0.339013</td>\n",
       "      <td>0.341925</td>\n",
       "      <td>0.305741</td>\n",
       "      <td>0.277654</td>\n",
       "      <td>0.239917</td>\n",
       "      <td>0.376330</td>\n",
       "      <td>0.902877</td>\n",
       "      <td>...</td>\n",
       "      <td>0.436108</td>\n",
       "      <td>0.186117</td>\n",
       "      <td>0.973098</td>\n",
       "      <td>0.174563</td>\n",
       "      <td>0.617365</td>\n",
       "      <td>0.400184</td>\n",
       "      <td>0.205172</td>\n",
       "      <td>0.681002</td>\n",
       "      <td>0.240516</td>\n",
       "      <td>0.309937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.044386</td>\n",
       "      <td>0.906664</td>\n",
       "      <td>0.741609</td>\n",
       "      <td>0.484974</td>\n",
       "      <td>0.939163</td>\n",
       "      <td>0.915193</td>\n",
       "      <td>0.190551</td>\n",
       "      <td>0.045356</td>\n",
       "      <td>0.801730</td>\n",
       "      <td>0.749827</td>\n",
       "      <td>...</td>\n",
       "      <td>0.060649</td>\n",
       "      <td>0.357373</td>\n",
       "      <td>0.803948</td>\n",
       "      <td>0.301519</td>\n",
       "      <td>0.138603</td>\n",
       "      <td>0.092428</td>\n",
       "      <td>0.159836</td>\n",
       "      <td>0.232201</td>\n",
       "      <td>0.383786</td>\n",
       "      <td>0.166437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.987995</td>\n",
       "      <td>0.080237</td>\n",
       "      <td>0.235766</td>\n",
       "      <td>0.945739</td>\n",
       "      <td>0.365186</td>\n",
       "      <td>0.599393</td>\n",
       "      <td>0.133799</td>\n",
       "      <td>0.599206</td>\n",
       "      <td>0.087360</td>\n",
       "      <td>0.954319</td>\n",
       "      <td>...</td>\n",
       "      <td>0.675147</td>\n",
       "      <td>0.969830</td>\n",
       "      <td>0.507953</td>\n",
       "      <td>0.398195</td>\n",
       "      <td>0.374054</td>\n",
       "      <td>0.157700</td>\n",
       "      <td>0.657808</td>\n",
       "      <td>0.306126</td>\n",
       "      <td>0.884177</td>\n",
       "      <td>0.897628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.538393</td>\n",
       "      <td>0.055874</td>\n",
       "      <td>0.701013</td>\n",
       "      <td>0.414923</td>\n",
       "      <td>0.770915</td>\n",
       "      <td>0.346280</td>\n",
       "      <td>0.442175</td>\n",
       "      <td>0.024295</td>\n",
       "      <td>0.557317</td>\n",
       "      <td>0.483933</td>\n",
       "      <td>...</td>\n",
       "      <td>0.433904</td>\n",
       "      <td>0.056358</td>\n",
       "      <td>0.051358</td>\n",
       "      <td>0.112115</td>\n",
       "      <td>0.626468</td>\n",
       "      <td>0.729211</td>\n",
       "      <td>0.053927</td>\n",
       "      <td>0.599942</td>\n",
       "      <td>0.344724</td>\n",
       "      <td>0.117280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.700939</td>\n",
       "      <td>0.329173</td>\n",
       "      <td>0.745502</td>\n",
       "      <td>0.620308</td>\n",
       "      <td>0.549649</td>\n",
       "      <td>0.453354</td>\n",
       "      <td>0.246234</td>\n",
       "      <td>0.091731</td>\n",
       "      <td>0.055652</td>\n",
       "      <td>0.809404</td>\n",
       "      <td>...</td>\n",
       "      <td>0.954240</td>\n",
       "      <td>0.331968</td>\n",
       "      <td>0.867625</td>\n",
       "      <td>0.852857</td>\n",
       "      <td>0.595065</td>\n",
       "      <td>0.486392</td>\n",
       "      <td>0.499015</td>\n",
       "      <td>0.734412</td>\n",
       "      <td>0.939322</td>\n",
       "      <td>0.725478</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.806720</td>\n",
       "      <td>0.567746</td>\n",
       "      <td>0.654361</td>\n",
       "      <td>0.050405</td>\n",
       "      <td>0.816577</td>\n",
       "      <td>0.258917</td>\n",
       "      <td>0.838817</td>\n",
       "      <td>0.658233</td>\n",
       "      <td>0.323597</td>\n",
       "      <td>0.448799</td>\n",
       "      <td>...</td>\n",
       "      <td>0.814698</td>\n",
       "      <td>0.056022</td>\n",
       "      <td>0.087960</td>\n",
       "      <td>0.584238</td>\n",
       "      <td>0.799250</td>\n",
       "      <td>0.457099</td>\n",
       "      <td>0.357334</td>\n",
       "      <td>0.866179</td>\n",
       "      <td>0.385506</td>\n",
       "      <td>0.067705</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.170651</td>\n",
       "      <td>0.687528</td>\n",
       "      <td>0.047279</td>\n",
       "      <td>0.939306</td>\n",
       "      <td>0.363779</td>\n",
       "      <td>0.886433</td>\n",
       "      <td>0.964445</td>\n",
       "      <td>0.990185</td>\n",
       "      <td>0.593928</td>\n",
       "      <td>0.006169</td>\n",
       "      <td>...</td>\n",
       "      <td>0.037594</td>\n",
       "      <td>0.826642</td>\n",
       "      <td>0.396922</td>\n",
       "      <td>0.022947</td>\n",
       "      <td>0.048749</td>\n",
       "      <td>0.715483</td>\n",
       "      <td>0.449759</td>\n",
       "      <td>0.282260</td>\n",
       "      <td>0.550810</td>\n",
       "      <td>0.665385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.316330</td>\n",
       "      <td>0.342875</td>\n",
       "      <td>0.964879</td>\n",
       "      <td>0.596836</td>\n",
       "      <td>0.699192</td>\n",
       "      <td>0.629405</td>\n",
       "      <td>0.273308</td>\n",
       "      <td>0.678529</td>\n",
       "      <td>0.461800</td>\n",
       "      <td>0.365946</td>\n",
       "      <td>...</td>\n",
       "      <td>0.929327</td>\n",
       "      <td>0.842726</td>\n",
       "      <td>0.470282</td>\n",
       "      <td>0.872041</td>\n",
       "      <td>0.010394</td>\n",
       "      <td>0.393490</td>\n",
       "      <td>0.901650</td>\n",
       "      <td>0.395684</td>\n",
       "      <td>0.913801</td>\n",
       "      <td>0.679611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.122060</td>\n",
       "      <td>0.384418</td>\n",
       "      <td>0.296389</td>\n",
       "      <td>0.697678</td>\n",
       "      <td>0.710351</td>\n",
       "      <td>0.751191</td>\n",
       "      <td>0.130311</td>\n",
       "      <td>0.039085</td>\n",
       "      <td>0.799461</td>\n",
       "      <td>0.937090</td>\n",
       "      <td>...</td>\n",
       "      <td>0.875597</td>\n",
       "      <td>0.676847</td>\n",
       "      <td>0.669087</td>\n",
       "      <td>0.194079</td>\n",
       "      <td>0.614823</td>\n",
       "      <td>0.071829</td>\n",
       "      <td>0.569117</td>\n",
       "      <td>0.155288</td>\n",
       "      <td>0.393337</td>\n",
       "      <td>0.626217</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          a         b         c         d         e         f         g  \\\n",
       "0  0.950685  0.645378  0.313912  0.736112  0.857305  0.374970  0.234014   \n",
       "1  0.696237  0.926854  0.188815  0.339013  0.341925  0.305741  0.277654   \n",
       "2  0.044386  0.906664  0.741609  0.484974  0.939163  0.915193  0.190551   \n",
       "3  0.987995  0.080237  0.235766  0.945739  0.365186  0.599393  0.133799   \n",
       "4  0.538393  0.055874  0.701013  0.414923  0.770915  0.346280  0.442175   \n",
       "5  0.700939  0.329173  0.745502  0.620308  0.549649  0.453354  0.246234   \n",
       "6  0.806720  0.567746  0.654361  0.050405  0.816577  0.258917  0.838817   \n",
       "7  0.170651  0.687528  0.047279  0.939306  0.363779  0.886433  0.964445   \n",
       "8  0.316330  0.342875  0.964879  0.596836  0.699192  0.629405  0.273308   \n",
       "9  0.122060  0.384418  0.296389  0.697678  0.710351  0.751191  0.130311   \n",
       "\n",
       "          h         i         j  ...         p         q         r         s  \\\n",
       "0  0.782537  0.342148  0.522992  ...  0.050619  0.453605  0.270995  0.031629   \n",
       "1  0.239917  0.376330  0.902877  ...  0.436108  0.186117  0.973098  0.174563   \n",
       "2  0.045356  0.801730  0.749827  ...  0.060649  0.357373  0.803948  0.301519   \n",
       "3  0.599206  0.087360  0.954319  ...  0.675147  0.969830  0.507953  0.398195   \n",
       "4  0.024295  0.557317  0.483933  ...  0.433904  0.056358  0.051358  0.112115   \n",
       "5  0.091731  0.055652  0.809404  ...  0.954240  0.331968  0.867625  0.852857   \n",
       "6  0.658233  0.323597  0.448799  ...  0.814698  0.056022  0.087960  0.584238   \n",
       "7  0.990185  0.593928  0.006169  ...  0.037594  0.826642  0.396922  0.022947   \n",
       "8  0.678529  0.461800  0.365946  ...  0.929327  0.842726  0.470282  0.872041   \n",
       "9  0.039085  0.799461  0.937090  ...  0.875597  0.676847  0.669087  0.194079   \n",
       "\n",
       "          t         u         v         w         x         y  \n",
       "0  0.574733  0.897325  0.501739  0.656413  0.899499  0.601801  \n",
       "1  0.617365  0.400184  0.205172  0.681002  0.240516  0.309937  \n",
       "2  0.138603  0.092428  0.159836  0.232201  0.383786  0.166437  \n",
       "3  0.374054  0.157700  0.657808  0.306126  0.884177  0.897628  \n",
       "4  0.626468  0.729211  0.053927  0.599942  0.344724  0.117280  \n",
       "5  0.595065  0.486392  0.499015  0.734412  0.939322  0.725478  \n",
       "6  0.799250  0.457099  0.357334  0.866179  0.385506  0.067705  \n",
       "7  0.048749  0.715483  0.449759  0.282260  0.550810  0.665385  \n",
       "8  0.010394  0.393490  0.901650  0.395684  0.913801  0.679611  \n",
       "9  0.614823  0.071829  0.569117  0.155288  0.393337  0.626217  \n",
       "\n",
       "[10 rows x 25 columns]"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# creating a new df\n",
    "df = pd.DataFrame(np.random.rand(200,25), columns=list('abcdefghijklmnopqrstuvwxy'))\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>0.950685</td>\n",
       "      <td>0.696237</td>\n",
       "      <td>0.044386</td>\n",
       "      <td>0.987995</td>\n",
       "      <td>0.538393</td>\n",
       "      <td>0.700939</td>\n",
       "      <td>0.806720</td>\n",
       "      <td>0.170651</td>\n",
       "      <td>0.316330</td>\n",
       "      <td>0.122060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0.645378</td>\n",
       "      <td>0.926854</td>\n",
       "      <td>0.906664</td>\n",
       "      <td>0.080237</td>\n",
       "      <td>0.055874</td>\n",
       "      <td>0.329173</td>\n",
       "      <td>0.567746</td>\n",
       "      <td>0.687528</td>\n",
       "      <td>0.342875</td>\n",
       "      <td>0.384418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>0.313912</td>\n",
       "      <td>0.188815</td>\n",
       "      <td>0.741609</td>\n",
       "      <td>0.235766</td>\n",
       "      <td>0.701013</td>\n",
       "      <td>0.745502</td>\n",
       "      <td>0.654361</td>\n",
       "      <td>0.047279</td>\n",
       "      <td>0.964879</td>\n",
       "      <td>0.296389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>0.736112</td>\n",
       "      <td>0.339013</td>\n",
       "      <td>0.484974</td>\n",
       "      <td>0.945739</td>\n",
       "      <td>0.414923</td>\n",
       "      <td>0.620308</td>\n",
       "      <td>0.050405</td>\n",
       "      <td>0.939306</td>\n",
       "      <td>0.596836</td>\n",
       "      <td>0.697678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>0.857305</td>\n",
       "      <td>0.341925</td>\n",
       "      <td>0.939163</td>\n",
       "      <td>0.365186</td>\n",
       "      <td>0.770915</td>\n",
       "      <td>0.549649</td>\n",
       "      <td>0.816577</td>\n",
       "      <td>0.363779</td>\n",
       "      <td>0.699192</td>\n",
       "      <td>0.710351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>0.374970</td>\n",
       "      <td>0.305741</td>\n",
       "      <td>0.915193</td>\n",
       "      <td>0.599393</td>\n",
       "      <td>0.346280</td>\n",
       "      <td>0.453354</td>\n",
       "      <td>0.258917</td>\n",
       "      <td>0.886433</td>\n",
       "      <td>0.629405</td>\n",
       "      <td>0.751191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>0.234014</td>\n",
       "      <td>0.277654</td>\n",
       "      <td>0.190551</td>\n",
       "      <td>0.133799</td>\n",
       "      <td>0.442175</td>\n",
       "      <td>0.246234</td>\n",
       "      <td>0.838817</td>\n",
       "      <td>0.964445</td>\n",
       "      <td>0.273308</td>\n",
       "      <td>0.130311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>0.782537</td>\n",
       "      <td>0.239917</td>\n",
       "      <td>0.045356</td>\n",
       "      <td>0.599206</td>\n",
       "      <td>0.024295</td>\n",
       "      <td>0.091731</td>\n",
       "      <td>0.658233</td>\n",
       "      <td>0.990185</td>\n",
       "      <td>0.678529</td>\n",
       "      <td>0.039085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>0.342148</td>\n",
       "      <td>0.376330</td>\n",
       "      <td>0.801730</td>\n",
       "      <td>0.087360</td>\n",
       "      <td>0.557317</td>\n",
       "      <td>0.055652</td>\n",
       "      <td>0.323597</td>\n",
       "      <td>0.593928</td>\n",
       "      <td>0.461800</td>\n",
       "      <td>0.799461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>0.522992</td>\n",
       "      <td>0.902877</td>\n",
       "      <td>0.749827</td>\n",
       "      <td>0.954319</td>\n",
       "      <td>0.483933</td>\n",
       "      <td>0.809404</td>\n",
       "      <td>0.448799</td>\n",
       "      <td>0.006169</td>\n",
       "      <td>0.365946</td>\n",
       "      <td>0.937090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>k</th>\n",
       "      <td>0.917537</td>\n",
       "      <td>0.689981</td>\n",
       "      <td>0.439928</td>\n",
       "      <td>0.882567</td>\n",
       "      <td>0.834639</td>\n",
       "      <td>0.607243</td>\n",
       "      <td>0.119689</td>\n",
       "      <td>0.582756</td>\n",
       "      <td>0.183779</td>\n",
       "      <td>0.845660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>l</th>\n",
       "      <td>0.342324</td>\n",
       "      <td>0.091354</td>\n",
       "      <td>0.493517</td>\n",
       "      <td>0.303911</td>\n",
       "      <td>0.575954</td>\n",
       "      <td>0.891187</td>\n",
       "      <td>0.025565</td>\n",
       "      <td>0.223219</td>\n",
       "      <td>0.467744</td>\n",
       "      <td>0.149833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>m</th>\n",
       "      <td>0.755472</td>\n",
       "      <td>0.290128</td>\n",
       "      <td>0.045039</td>\n",
       "      <td>0.831454</td>\n",
       "      <td>0.562597</td>\n",
       "      <td>0.453678</td>\n",
       "      <td>0.096329</td>\n",
       "      <td>0.462066</td>\n",
       "      <td>0.163871</td>\n",
       "      <td>0.416048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>0.454898</td>\n",
       "      <td>0.367385</td>\n",
       "      <td>0.902142</td>\n",
       "      <td>0.979621</td>\n",
       "      <td>0.151888</td>\n",
       "      <td>0.724248</td>\n",
       "      <td>0.208895</td>\n",
       "      <td>0.849071</td>\n",
       "      <td>0.161992</td>\n",
       "      <td>0.056626</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>0.049696</td>\n",
       "      <td>0.245750</td>\n",
       "      <td>0.505337</td>\n",
       "      <td>0.381966</td>\n",
       "      <td>0.681712</td>\n",
       "      <td>0.480053</td>\n",
       "      <td>0.313002</td>\n",
       "      <td>0.408207</td>\n",
       "      <td>0.850392</td>\n",
       "      <td>0.402682</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>p</th>\n",
       "      <td>0.050619</td>\n",
       "      <td>0.436108</td>\n",
       "      <td>0.060649</td>\n",
       "      <td>0.675147</td>\n",
       "      <td>0.433904</td>\n",
       "      <td>0.954240</td>\n",
       "      <td>0.814698</td>\n",
       "      <td>0.037594</td>\n",
       "      <td>0.929327</td>\n",
       "      <td>0.875597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>0.453605</td>\n",
       "      <td>0.186117</td>\n",
       "      <td>0.357373</td>\n",
       "      <td>0.969830</td>\n",
       "      <td>0.056358</td>\n",
       "      <td>0.331968</td>\n",
       "      <td>0.056022</td>\n",
       "      <td>0.826642</td>\n",
       "      <td>0.842726</td>\n",
       "      <td>0.676847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>0.270995</td>\n",
       "      <td>0.973098</td>\n",
       "      <td>0.803948</td>\n",
       "      <td>0.507953</td>\n",
       "      <td>0.051358</td>\n",
       "      <td>0.867625</td>\n",
       "      <td>0.087960</td>\n",
       "      <td>0.396922</td>\n",
       "      <td>0.470282</td>\n",
       "      <td>0.669087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>0.031629</td>\n",
       "      <td>0.174563</td>\n",
       "      <td>0.301519</td>\n",
       "      <td>0.398195</td>\n",
       "      <td>0.112115</td>\n",
       "      <td>0.852857</td>\n",
       "      <td>0.584238</td>\n",
       "      <td>0.022947</td>\n",
       "      <td>0.872041</td>\n",
       "      <td>0.194079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>0.574733</td>\n",
       "      <td>0.617365</td>\n",
       "      <td>0.138603</td>\n",
       "      <td>0.374054</td>\n",
       "      <td>0.626468</td>\n",
       "      <td>0.595065</td>\n",
       "      <td>0.799250</td>\n",
       "      <td>0.048749</td>\n",
       "      <td>0.010394</td>\n",
       "      <td>0.614823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>0.897325</td>\n",
       "      <td>0.400184</td>\n",
       "      <td>0.092428</td>\n",
       "      <td>0.157700</td>\n",
       "      <td>0.729211</td>\n",
       "      <td>0.486392</td>\n",
       "      <td>0.457099</td>\n",
       "      <td>0.715483</td>\n",
       "      <td>0.393490</td>\n",
       "      <td>0.071829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>0.501739</td>\n",
       "      <td>0.205172</td>\n",
       "      <td>0.159836</td>\n",
       "      <td>0.657808</td>\n",
       "      <td>0.053927</td>\n",
       "      <td>0.499015</td>\n",
       "      <td>0.357334</td>\n",
       "      <td>0.449759</td>\n",
       "      <td>0.901650</td>\n",
       "      <td>0.569117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>0.656413</td>\n",
       "      <td>0.681002</td>\n",
       "      <td>0.232201</td>\n",
       "      <td>0.306126</td>\n",
       "      <td>0.599942</td>\n",
       "      <td>0.734412</td>\n",
       "      <td>0.866179</td>\n",
       "      <td>0.282260</td>\n",
       "      <td>0.395684</td>\n",
       "      <td>0.155288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>x</th>\n",
       "      <td>0.899499</td>\n",
       "      <td>0.240516</td>\n",
       "      <td>0.383786</td>\n",
       "      <td>0.884177</td>\n",
       "      <td>0.344724</td>\n",
       "      <td>0.939322</td>\n",
       "      <td>0.385506</td>\n",
       "      <td>0.550810</td>\n",
       "      <td>0.913801</td>\n",
       "      <td>0.393337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>0.601801</td>\n",
       "      <td>0.309937</td>\n",
       "      <td>0.166437</td>\n",
       "      <td>0.897628</td>\n",
       "      <td>0.117280</td>\n",
       "      <td>0.725478</td>\n",
       "      <td>0.067705</td>\n",
       "      <td>0.665385</td>\n",
       "      <td>0.679611</td>\n",
       "      <td>0.626217</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6  \\\n",
       "a  0.950685  0.696237  0.044386  0.987995  0.538393  0.700939  0.806720   \n",
       "b  0.645378  0.926854  0.906664  0.080237  0.055874  0.329173  0.567746   \n",
       "c  0.313912  0.188815  0.741609  0.235766  0.701013  0.745502  0.654361   \n",
       "d  0.736112  0.339013  0.484974  0.945739  0.414923  0.620308  0.050405   \n",
       "e  0.857305  0.341925  0.939163  0.365186  0.770915  0.549649  0.816577   \n",
       "f  0.374970  0.305741  0.915193  0.599393  0.346280  0.453354  0.258917   \n",
       "g  0.234014  0.277654  0.190551  0.133799  0.442175  0.246234  0.838817   \n",
       "h  0.782537  0.239917  0.045356  0.599206  0.024295  0.091731  0.658233   \n",
       "i  0.342148  0.376330  0.801730  0.087360  0.557317  0.055652  0.323597   \n",
       "j  0.522992  0.902877  0.749827  0.954319  0.483933  0.809404  0.448799   \n",
       "k  0.917537  0.689981  0.439928  0.882567  0.834639  0.607243  0.119689   \n",
       "l  0.342324  0.091354  0.493517  0.303911  0.575954  0.891187  0.025565   \n",
       "m  0.755472  0.290128  0.045039  0.831454  0.562597  0.453678  0.096329   \n",
       "n  0.454898  0.367385  0.902142  0.979621  0.151888  0.724248  0.208895   \n",
       "o  0.049696  0.245750  0.505337  0.381966  0.681712  0.480053  0.313002   \n",
       "p  0.050619  0.436108  0.060649  0.675147  0.433904  0.954240  0.814698   \n",
       "q  0.453605  0.186117  0.357373  0.969830  0.056358  0.331968  0.056022   \n",
       "r  0.270995  0.973098  0.803948  0.507953  0.051358  0.867625  0.087960   \n",
       "s  0.031629  0.174563  0.301519  0.398195  0.112115  0.852857  0.584238   \n",
       "t  0.574733  0.617365  0.138603  0.374054  0.626468  0.595065  0.799250   \n",
       "u  0.897325  0.400184  0.092428  0.157700  0.729211  0.486392  0.457099   \n",
       "v  0.501739  0.205172  0.159836  0.657808  0.053927  0.499015  0.357334   \n",
       "w  0.656413  0.681002  0.232201  0.306126  0.599942  0.734412  0.866179   \n",
       "x  0.899499  0.240516  0.383786  0.884177  0.344724  0.939322  0.385506   \n",
       "y  0.601801  0.309937  0.166437  0.897628  0.117280  0.725478  0.067705   \n",
       "\n",
       "          7         8         9  \n",
       "a  0.170651  0.316330  0.122060  \n",
       "b  0.687528  0.342875  0.384418  \n",
       "c  0.047279  0.964879  0.296389  \n",
       "d  0.939306  0.596836  0.697678  \n",
       "e  0.363779  0.699192  0.710351  \n",
       "f  0.886433  0.629405  0.751191  \n",
       "g  0.964445  0.273308  0.130311  \n",
       "h  0.990185  0.678529  0.039085  \n",
       "i  0.593928  0.461800  0.799461  \n",
       "j  0.006169  0.365946  0.937090  \n",
       "k  0.582756  0.183779  0.845660  \n",
       "l  0.223219  0.467744  0.149833  \n",
       "m  0.462066  0.163871  0.416048  \n",
       "n  0.849071  0.161992  0.056626  \n",
       "o  0.408207  0.850392  0.402682  \n",
       "p  0.037594  0.929327  0.875597  \n",
       "q  0.826642  0.842726  0.676847  \n",
       "r  0.396922  0.470282  0.669087  \n",
       "s  0.022947  0.872041  0.194079  \n",
       "t  0.048749  0.010394  0.614823  \n",
       "u  0.715483  0.393490  0.071829  \n",
       "v  0.449759  0.901650  0.569117  \n",
       "w  0.282260  0.395684  0.155288  \n",
       "x  0.550810  0.913801  0.393337  \n",
       "y  0.665385  0.679611  0.626217  "
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(10).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>d</th>\n",
       "      <th>e</th>\n",
       "      <th>f</th>\n",
       "      <th>g</th>\n",
       "      <th>h</th>\n",
       "      <th>i</th>\n",
       "      <th>j</th>\n",
       "      <th>...</th>\n",
       "      <th>p</th>\n",
       "      <th>q</th>\n",
       "      <th>r</th>\n",
       "      <th>s</th>\n",
       "      <th>t</th>\n",
       "      <th>u</th>\n",
       "      <th>v</th>\n",
       "      <th>w</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>200.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.487481</td>\n",
       "      <td>0.507299</td>\n",
       "      <td>0.479755</td>\n",
       "      <td>0.504977</td>\n",
       "      <td>0.490151</td>\n",
       "      <td>0.499596</td>\n",
       "      <td>0.502276</td>\n",
       "      <td>0.510397</td>\n",
       "      <td>0.491671</td>\n",
       "      <td>0.484183</td>\n",
       "      <td>...</td>\n",
       "      <td>0.497244</td>\n",
       "      <td>0.497249</td>\n",
       "      <td>0.488058</td>\n",
       "      <td>0.501489</td>\n",
       "      <td>0.479454</td>\n",
       "      <td>0.468368</td>\n",
       "      <td>0.501942</td>\n",
       "      <td>0.478820</td>\n",
       "      <td>0.507582</td>\n",
       "      <td>0.508898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.307421</td>\n",
       "      <td>0.278305</td>\n",
       "      <td>0.290530</td>\n",
       "      <td>0.291829</td>\n",
       "      <td>0.294614</td>\n",
       "      <td>0.273423</td>\n",
       "      <td>0.289458</td>\n",
       "      <td>0.297787</td>\n",
       "      <td>0.288558</td>\n",
       "      <td>0.294799</td>\n",
       "      <td>...</td>\n",
       "      <td>0.283147</td>\n",
       "      <td>0.296267</td>\n",
       "      <td>0.287999</td>\n",
       "      <td>0.272811</td>\n",
       "      <td>0.283131</td>\n",
       "      <td>0.290876</td>\n",
       "      <td>0.283854</td>\n",
       "      <td>0.283145</td>\n",
       "      <td>0.294164</td>\n",
       "      <td>0.303982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.012917</td>\n",
       "      <td>0.016089</td>\n",
       "      <td>0.024319</td>\n",
       "      <td>0.007126</td>\n",
       "      <td>0.000596</td>\n",
       "      <td>0.000767</td>\n",
       "      <td>0.000891</td>\n",
       "      <td>0.002252</td>\n",
       "      <td>0.002700</td>\n",
       "      <td>0.005395</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000828</td>\n",
       "      <td>0.001314</td>\n",
       "      <td>0.002628</td>\n",
       "      <td>0.019507</td>\n",
       "      <td>0.010394</td>\n",
       "      <td>0.003276</td>\n",
       "      <td>0.001885</td>\n",
       "      <td>0.002685</td>\n",
       "      <td>0.003099</td>\n",
       "      <td>0.000232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.222616</td>\n",
       "      <td>0.271825</td>\n",
       "      <td>0.217836</td>\n",
       "      <td>0.263322</td>\n",
       "      <td>0.250964</td>\n",
       "      <td>0.268221</td>\n",
       "      <td>0.245639</td>\n",
       "      <td>0.240951</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>0.233461</td>\n",
       "      <td>...</td>\n",
       "      <td>0.277994</td>\n",
       "      <td>0.244560</td>\n",
       "      <td>0.245039</td>\n",
       "      <td>0.292980</td>\n",
       "      <td>0.252936</td>\n",
       "      <td>0.215931</td>\n",
       "      <td>0.277212</td>\n",
       "      <td>0.240684</td>\n",
       "      <td>0.249865</td>\n",
       "      <td>0.214125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.474311</td>\n",
       "      <td>0.505550</td>\n",
       "      <td>0.478239</td>\n",
       "      <td>0.509991</td>\n",
       "      <td>0.493848</td>\n",
       "      <td>0.471160</td>\n",
       "      <td>0.492809</td>\n",
       "      <td>0.529968</td>\n",
       "      <td>0.507740</td>\n",
       "      <td>0.457930</td>\n",
       "      <td>...</td>\n",
       "      <td>0.515958</td>\n",
       "      <td>0.481093</td>\n",
       "      <td>0.483948</td>\n",
       "      <td>0.505265</td>\n",
       "      <td>0.472656</td>\n",
       "      <td>0.456308</td>\n",
       "      <td>0.499269</td>\n",
       "      <td>0.459450</td>\n",
       "      <td>0.481182</td>\n",
       "      <td>0.518171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.759086</td>\n",
       "      <td>0.742708</td>\n",
       "      <td>0.742582</td>\n",
       "      <td>0.747384</td>\n",
       "      <td>0.746684</td>\n",
       "      <td>0.714832</td>\n",
       "      <td>0.769089</td>\n",
       "      <td>0.767614</td>\n",
       "      <td>0.733958</td>\n",
       "      <td>0.764846</td>\n",
       "      <td>...</td>\n",
       "      <td>0.723277</td>\n",
       "      <td>0.770895</td>\n",
       "      <td>0.743287</td>\n",
       "      <td>0.727175</td>\n",
       "      <td>0.731588</td>\n",
       "      <td>0.718237</td>\n",
       "      <td>0.732999</td>\n",
       "      <td>0.726286</td>\n",
       "      <td>0.770076</td>\n",
       "      <td>0.759389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>0.997688</td>\n",
       "      <td>0.999280</td>\n",
       "      <td>0.988486</td>\n",
       "      <td>0.997999</td>\n",
       "      <td>0.999103</td>\n",
       "      <td>0.992287</td>\n",
       "      <td>0.991735</td>\n",
       "      <td>0.998825</td>\n",
       "      <td>0.999992</td>\n",
       "      <td>0.986358</td>\n",
       "      <td>...</td>\n",
       "      <td>0.997158</td>\n",
       "      <td>0.995699</td>\n",
       "      <td>0.996585</td>\n",
       "      <td>0.997093</td>\n",
       "      <td>0.987976</td>\n",
       "      <td>0.993351</td>\n",
       "      <td>0.988602</td>\n",
       "      <td>0.977097</td>\n",
       "      <td>0.990872</td>\n",
       "      <td>0.998514</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                a           b           c           d           e           f  \\\n",
       "count  200.000000  200.000000  200.000000  200.000000  200.000000  200.000000   \n",
       "mean     0.487481    0.507299    0.479755    0.504977    0.490151    0.499596   \n",
       "std      0.307421    0.278305    0.290530    0.291829    0.294614    0.273423   \n",
       "min      0.012917    0.016089    0.024319    0.007126    0.000596    0.000767   \n",
       "25%      0.222616    0.271825    0.217836    0.263322    0.250964    0.268221   \n",
       "50%      0.474311    0.505550    0.478239    0.509991    0.493848    0.471160   \n",
       "75%      0.759086    0.742708    0.742582    0.747384    0.746684    0.714832   \n",
       "max      0.997688    0.999280    0.988486    0.997999    0.999103    0.992287   \n",
       "\n",
       "                g           h           i           j  ...           p  \\\n",
       "count  200.000000  200.000000  200.000000  200.000000  ...  200.000000   \n",
       "mean     0.502276    0.510397    0.491671    0.484183  ...    0.497244   \n",
       "std      0.289458    0.297787    0.288558    0.294799  ...    0.283147   \n",
       "min      0.000891    0.002252    0.002700    0.005395  ...    0.000828   \n",
       "25%      0.245639    0.240951    0.248309    0.233461  ...    0.277994   \n",
       "50%      0.492809    0.529968    0.507740    0.457930  ...    0.515958   \n",
       "75%      0.769089    0.767614    0.733958    0.764846  ...    0.723277   \n",
       "max      0.991735    0.998825    0.999992    0.986358  ...    0.997158   \n",
       "\n",
       "                q           r           s           t           u           v  \\\n",
       "count  200.000000  200.000000  200.000000  200.000000  200.000000  200.000000   \n",
       "mean     0.497249    0.488058    0.501489    0.479454    0.468368    0.501942   \n",
       "std      0.296267    0.287999    0.272811    0.283131    0.290876    0.283854   \n",
       "min      0.001314    0.002628    0.019507    0.010394    0.003276    0.001885   \n",
       "25%      0.244560    0.245039    0.292980    0.252936    0.215931    0.277212   \n",
       "50%      0.481093    0.483948    0.505265    0.472656    0.456308    0.499269   \n",
       "75%      0.770895    0.743287    0.727175    0.731588    0.718237    0.732999   \n",
       "max      0.995699    0.996585    0.997093    0.987976    0.993351    0.988602   \n",
       "\n",
       "                w           x           y  \n",
       "count  200.000000  200.000000  200.000000  \n",
       "mean     0.478820    0.507582    0.508898  \n",
       "std      0.283145    0.294164    0.303982  \n",
       "min      0.002685    0.003099    0.000232  \n",
       "25%      0.240684    0.249865    0.214125  \n",
       "50%      0.459450    0.481182    0.518171  \n",
       "75%      0.726286    0.770076    0.759389  \n",
       "max      0.977097    0.990872    0.998514  \n",
       "\n",
       "[8 rows x 25 columns]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.487481</td>\n",
       "      <td>0.307421</td>\n",
       "      <td>0.012917</td>\n",
       "      <td>0.222616</td>\n",
       "      <td>0.474311</td>\n",
       "      <td>0.759086</td>\n",
       "      <td>0.997688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.507299</td>\n",
       "      <td>0.278305</td>\n",
       "      <td>0.016089</td>\n",
       "      <td>0.271825</td>\n",
       "      <td>0.505550</td>\n",
       "      <td>0.742708</td>\n",
       "      <td>0.999280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.479755</td>\n",
       "      <td>0.290530</td>\n",
       "      <td>0.024319</td>\n",
       "      <td>0.217836</td>\n",
       "      <td>0.478239</td>\n",
       "      <td>0.742582</td>\n",
       "      <td>0.988486</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.504977</td>\n",
       "      <td>0.291829</td>\n",
       "      <td>0.007126</td>\n",
       "      <td>0.263322</td>\n",
       "      <td>0.509991</td>\n",
       "      <td>0.747384</td>\n",
       "      <td>0.997999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>e</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.490151</td>\n",
       "      <td>0.294614</td>\n",
       "      <td>0.000596</td>\n",
       "      <td>0.250964</td>\n",
       "      <td>0.493848</td>\n",
       "      <td>0.746684</td>\n",
       "      <td>0.999103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>f</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.499596</td>\n",
       "      <td>0.273423</td>\n",
       "      <td>0.000767</td>\n",
       "      <td>0.268221</td>\n",
       "      <td>0.471160</td>\n",
       "      <td>0.714832</td>\n",
       "      <td>0.992287</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>g</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.502276</td>\n",
       "      <td>0.289458</td>\n",
       "      <td>0.000891</td>\n",
       "      <td>0.245639</td>\n",
       "      <td>0.492809</td>\n",
       "      <td>0.769089</td>\n",
       "      <td>0.991735</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>h</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.510397</td>\n",
       "      <td>0.297787</td>\n",
       "      <td>0.002252</td>\n",
       "      <td>0.240951</td>\n",
       "      <td>0.529968</td>\n",
       "      <td>0.767614</td>\n",
       "      <td>0.998825</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>i</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.491671</td>\n",
       "      <td>0.288558</td>\n",
       "      <td>0.002700</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>0.507740</td>\n",
       "      <td>0.733958</td>\n",
       "      <td>0.999992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>j</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.484183</td>\n",
       "      <td>0.294799</td>\n",
       "      <td>0.005395</td>\n",
       "      <td>0.233461</td>\n",
       "      <td>0.457930</td>\n",
       "      <td>0.764846</td>\n",
       "      <td>0.986358</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>k</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.515154</td>\n",
       "      <td>0.295868</td>\n",
       "      <td>0.012320</td>\n",
       "      <td>0.272132</td>\n",
       "      <td>0.509479</td>\n",
       "      <td>0.768550</td>\n",
       "      <td>0.999960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>l</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.507969</td>\n",
       "      <td>0.308161</td>\n",
       "      <td>0.001847</td>\n",
       "      <td>0.243705</td>\n",
       "      <td>0.528413</td>\n",
       "      <td>0.797866</td>\n",
       "      <td>0.998259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>m</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.519328</td>\n",
       "      <td>0.287071</td>\n",
       "      <td>0.000957</td>\n",
       "      <td>0.287781</td>\n",
       "      <td>0.482635</td>\n",
       "      <td>0.783235</td>\n",
       "      <td>0.995021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>n</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.498325</td>\n",
       "      <td>0.293948</td>\n",
       "      <td>0.000355</td>\n",
       "      <td>0.249863</td>\n",
       "      <td>0.531101</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>0.997070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>o</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.509817</td>\n",
       "      <td>0.282540</td>\n",
       "      <td>0.005002</td>\n",
       "      <td>0.286221</td>\n",
       "      <td>0.505166</td>\n",
       "      <td>0.740807</td>\n",
       "      <td>0.999571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>p</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.497244</td>\n",
       "      <td>0.283147</td>\n",
       "      <td>0.000828</td>\n",
       "      <td>0.277994</td>\n",
       "      <td>0.515958</td>\n",
       "      <td>0.723277</td>\n",
       "      <td>0.997158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>q</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.497249</td>\n",
       "      <td>0.296267</td>\n",
       "      <td>0.001314</td>\n",
       "      <td>0.244560</td>\n",
       "      <td>0.481093</td>\n",
       "      <td>0.770895</td>\n",
       "      <td>0.995699</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.488058</td>\n",
       "      <td>0.287999</td>\n",
       "      <td>0.002628</td>\n",
       "      <td>0.245039</td>\n",
       "      <td>0.483948</td>\n",
       "      <td>0.743287</td>\n",
       "      <td>0.996585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>s</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.501489</td>\n",
       "      <td>0.272811</td>\n",
       "      <td>0.019507</td>\n",
       "      <td>0.292980</td>\n",
       "      <td>0.505265</td>\n",
       "      <td>0.727175</td>\n",
       "      <td>0.997093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>t</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.479454</td>\n",
       "      <td>0.283131</td>\n",
       "      <td>0.010394</td>\n",
       "      <td>0.252936</td>\n",
       "      <td>0.472656</td>\n",
       "      <td>0.731588</td>\n",
       "      <td>0.987976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>u</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.468368</td>\n",
       "      <td>0.290876</td>\n",
       "      <td>0.003276</td>\n",
       "      <td>0.215931</td>\n",
       "      <td>0.456308</td>\n",
       "      <td>0.718237</td>\n",
       "      <td>0.993351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>v</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.501942</td>\n",
       "      <td>0.283854</td>\n",
       "      <td>0.001885</td>\n",
       "      <td>0.277212</td>\n",
       "      <td>0.499269</td>\n",
       "      <td>0.732999</td>\n",
       "      <td>0.988602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>w</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.478820</td>\n",
       "      <td>0.283145</td>\n",
       "      <td>0.002685</td>\n",
       "      <td>0.240684</td>\n",
       "      <td>0.459450</td>\n",
       "      <td>0.726286</td>\n",
       "      <td>0.977097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>x</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.507582</td>\n",
       "      <td>0.294164</td>\n",
       "      <td>0.003099</td>\n",
       "      <td>0.249865</td>\n",
       "      <td>0.481182</td>\n",
       "      <td>0.770076</td>\n",
       "      <td>0.990872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>y</th>\n",
       "      <td>200.0</td>\n",
       "      <td>0.508898</td>\n",
       "      <td>0.303982</td>\n",
       "      <td>0.000232</td>\n",
       "      <td>0.214125</td>\n",
       "      <td>0.518171</td>\n",
       "      <td>0.759389</td>\n",
       "      <td>0.998514</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   count      mean       std       min       25%       50%       75%       max\n",
       "a  200.0  0.487481  0.307421  0.012917  0.222616  0.474311  0.759086  0.997688\n",
       "b  200.0  0.507299  0.278305  0.016089  0.271825  0.505550  0.742708  0.999280\n",
       "c  200.0  0.479755  0.290530  0.024319  0.217836  0.478239  0.742582  0.988486\n",
       "d  200.0  0.504977  0.291829  0.007126  0.263322  0.509991  0.747384  0.997999\n",
       "e  200.0  0.490151  0.294614  0.000596  0.250964  0.493848  0.746684  0.999103\n",
       "f  200.0  0.499596  0.273423  0.000767  0.268221  0.471160  0.714832  0.992287\n",
       "g  200.0  0.502276  0.289458  0.000891  0.245639  0.492809  0.769089  0.991735\n",
       "h  200.0  0.510397  0.297787  0.002252  0.240951  0.529968  0.767614  0.998825\n",
       "i  200.0  0.491671  0.288558  0.002700  0.248309  0.507740  0.733958  0.999992\n",
       "j  200.0  0.484183  0.294799  0.005395  0.233461  0.457930  0.764846  0.986358\n",
       "k  200.0  0.515154  0.295868  0.012320  0.272132  0.509479  0.768550  0.999960\n",
       "l  200.0  0.507969  0.308161  0.001847  0.243705  0.528413  0.797866  0.998259\n",
       "m  200.0  0.519328  0.287071  0.000957  0.287781  0.482635  0.783235  0.995021\n",
       "n  200.0  0.498325  0.293948  0.000355  0.249863  0.531101  0.747875  0.997070\n",
       "o  200.0  0.509817  0.282540  0.005002  0.286221  0.505166  0.740807  0.999571\n",
       "p  200.0  0.497244  0.283147  0.000828  0.277994  0.515958  0.723277  0.997158\n",
       "q  200.0  0.497249  0.296267  0.001314  0.244560  0.481093  0.770895  0.995699\n",
       "r  200.0  0.488058  0.287999  0.002628  0.245039  0.483948  0.743287  0.996585\n",
       "s  200.0  0.501489  0.272811  0.019507  0.292980  0.505265  0.727175  0.997093\n",
       "t  200.0  0.479454  0.283131  0.010394  0.252936  0.472656  0.731588  0.987976\n",
       "u  200.0  0.468368  0.290876  0.003276  0.215931  0.456308  0.718237  0.993351\n",
       "v  200.0  0.501942  0.283854  0.001885  0.277212  0.499269  0.732999  0.988602\n",
       "w  200.0  0.478820  0.283145  0.002685  0.240684  0.459450  0.726286  0.977097\n",
       "x  200.0  0.507582  0.294164  0.003099  0.249865  0.481182  0.770076  0.990872\n",
       "y  200.0  0.508898  0.303982  0.000232  0.214125  0.518171  0.759389  0.998514"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe().T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 23- Reshaping a dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zip</th>\n",
       "      <th>factory</th>\n",
       "      <th>warehouse</th>\n",
       "      <th>retail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12345</td>\n",
       "      <td>100</td>\n",
       "      <td>200</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>34567</td>\n",
       "      <td>400</td>\n",
       "      <td>500</td>\n",
       "      <td>600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>67890</td>\n",
       "      <td>700</td>\n",
       "      <td>800</td>\n",
       "      <td>900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     zip  factory  warehouse  retail\n",
       "0  12345      100        200     300\n",
       "1  34567      400        500     600\n",
       "2  67890      700        800     900"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fasla = pd.DataFrame([['12345', 100, 200, 300], ['34567', 400, 500, 600], ['67890', 700, 800, 900]],\n",
    "                          columns=['zip', 'factory', 'warehouse', 'retail'])\n",
    "fasla.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "# fasla.head().T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>zip</th>\n",
       "      <th>location_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>12345</td>\n",
       "      <td>factory</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>34567</td>\n",
       "      <td>warehouse</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id    zip location_type\n",
       "0        1  12345       factory\n",
       "1        2  34567     warehouse"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fasla2 = pd.DataFrame([[1, '12345', 'factory'], [2, '34567', 'warehouse']],\n",
    "                      columns=['user_id', 'zip', 'location_type'])\n",
    "fasla2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zip</th>\n",
       "      <th>factory</th>\n",
       "      <th>warehouse</th>\n",
       "      <th>retail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12345</td>\n",
       "      <td>100</td>\n",
       "      <td>200</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>34567</td>\n",
       "      <td>400</td>\n",
       "      <td>500</td>\n",
       "      <td>600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>67890</td>\n",
       "      <td>700</td>\n",
       "      <td>800</td>\n",
       "      <td>900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     zip  factory  warehouse  retail\n",
       "0  12345      100        200     300\n",
       "1  34567      400        500     600\n",
       "2  67890      700        800     900"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fasla"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='zip', ylabel='factory'>"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "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",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.barplot(x='zip', y='factory', data=fasla)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>zip</th>\n",
       "      <th>location_type</th>\n",
       "      <th>distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12345</td>\n",
       "      <td>factory</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>34567</td>\n",
       "      <td>factory</td>\n",
       "      <td>400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>67890</td>\n",
       "      <td>factory</td>\n",
       "      <td>700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12345</td>\n",
       "      <td>warehouse</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34567</td>\n",
       "      <td>warehouse</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     zip location_type  distance\n",
       "0  12345       factory       100\n",
       "1  34567       factory       400\n",
       "2  67890       factory       700\n",
       "3  12345     warehouse       200\n",
       "4  34567     warehouse       500"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fasla_long = fasla.melt(id_vars='zip', var_name='location_type', value_name='distance')\n",
    "fasla_long.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "zip              object\n",
       "location_type    object\n",
       "distance          int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fasla_long.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='zip', ylabel='distance'>"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "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",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "sns.barplot(x='zip', y='distance', hue='location_type', data=fasla_long)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.2 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
